package com.wc.alorithm_luogu.P1160;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.StreamTokenizer;
import java.util.HashMap;

/**
 * @Author congge
 * @Date 2023/5/14 18:43
 * @description https://www.luogu.com.cn/problem/P1160
 * 队列安排
 */
public class Main {
    static Node head = new Node();

    public static void main(String[] args) {
        // 存储每一个学生的位置信息
        HashMap<Integer, Node> map = new HashMap<>();
        Input sc = new Input();

        head.val = 1;
        map.put(1, head);

        int n = sc.nextInt();

        // 输入的ID
        int inputId;
        // 输入的方向
        int option;

        for (int i = 2; i <= n; i++) {
            inputId = sc.nextInt();
            option = sc.nextInt();
            Node node = new Node();
            node.val = i;
            Node preNode = map.get(inputId);
            if (option == 0) {
                inLeft(preNode, node);
            } else {
                inRight(preNode, node);
            }
            map.put(i, node);
        }

        int m = sc.nextInt();
        for (int i = 0; i < m; i++) {
            inputId = sc.nextInt();
            delNode(map.remove(inputId));
        }

        StringBuilder ans = new StringBuilder();
        Node first = head;
        ans.append(first.val);
        first = first.right;

        while (first != null) {
            ans.append(' ');
            ans.append(first.val);
            first = first.right;
        }
        System.out.println(ans);
    }

    static class Input {
        StreamTokenizer in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));

        public int nextInt() {
            try {
                in.nextToken();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return (int) in.nval;
        }
    }

    static class Node {
        Node left;
        Node right;
        int val;
    }


    // 在node1左边插入node2
    public static void inLeft(Node node1, Node node2) {

        node2.right = node1;
        node2.left = node1.left;
        node1.left = node2;
        if (node1 == head) {
            head = node2;
            return;
        }
        node2.left.right = node2;
    }

    // 在node1右边插入node2
    public static void inRight(Node node1, Node node2) {
        node2.right = node1.right;
        node2.left = node1;
        node1.right = node2;
        if (node2.right == null) {
            return;
        }
        node2.right.left = node2;
    }

    public static void delNode(Node node) {
        if (node == null) {
            return;
        }

        if (node == head) {
            head = node.right;
            head.left = null;
            node.right = null;
            return;
        }

        Node leftNode = node.left;
        Node rightNode = node.right;

        leftNode.right = rightNode;
        if (rightNode != null) {
            rightNode.left = leftNode;
        }
        node.left = null;
        node.right = null;
    }
}
